<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>发布普通运价</title>
  </head>
  <body>
    <div id="form-ct-itemselector">
    </div>
    <script>
        Ext.onReady(function(){
            /*
             * Ext.ux.ItemSelector Example Code
             */
            Ext.form.Field.prototype.msgTarget = 'side';
            tabs.getItem(0).setTitle('普通运价维护');
            var airways = new Ext.form.ComboBox({
                store: new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getInternalAirways'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root',
                        id: 'id'
                    }, ['id', 'airways_name'])
                }),
                name: 'airways',
                loadingText: '正在加载...',
                displayField: 'airways_name',
                valueField: 'id',
                mode: 'remote',
                triggerAction: 'all',
                hiddenName: 'airways_id',
                fieldLabel: "<span class='red'>*</span>空港名称",
                emptyText: '请选择航空公司...',
                editable: false,
                allowBlank: false,
                width: 130,
                maxHeight: 150,
                tabIndex: 4
            });
                
            var airportFrom = new Ext.form.ComboBox({
                store: new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/getAllAirportComboBox'
                    }),
                    reader: new Ext.data.JsonReader({
                        root: 'root',
                        id: 'id'
                    }, ['id', 'airport_name'])
                }),
                name: 'airport_from',
                loadingText: '正在加载...',
                displayField: 'airport_name',
                valueField: 'id',
                mode: 'remote',
                triggerAction: 'all',
                hiddenName: 'airport_from_id',
                fieldLabel: '<span class="red">*</span>始发城市',
                emptyText: '请选择...',
                editable: false,
                allowBlank: false,
                width: 130,
                maxHeight: 150,
                tabIndex: 4
            });
                                
            var flights = new Ext.form.TextField({
                fieldLabel: '适用航班',
                //allowBlank: false,
                name: 'flights',
                anchor: '90%'
            });
                
            var discountFrom = new Ext.form.ComboBox({ //combobox   
                name: 'discount_from',
                fieldLabel: '<span class="red">*</span>折扣开始',
                width: '80',
                resiable: true,
                typeAhead: true,
                allowBlank: false,
                handleHeight: 100, //   
                displayField: 'key',
                valueField: 'value',
                selectOnFocus: true,
                mode: 'local',
                selectOnFocus: true,
                triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                readOnly: true,
                emptyText: '选择类型...',
                store: new Ext.data.Store({
                    data: [['45', '45折'], ['50', '50折'], ['55', '55折'], ['60', '60折'], ['65', '65折'], ['70', '70折'], ['75', '75折'], ['80', '80折']],
                    reader: new Ext.data.ArrayReader({
                        id: 0
                    }, [{
                            name: 'value'
                        }, {
                            name: 'key'
                        }])
                }), //数据储存到这个comboBox   
                anchor: '90%'
            });
                
            var discountTo = new Ext.form.ComboBox({ //combobox   
                name: 'discount_to',
                fieldLabel: '<span class="red">*</span>折扣结束',
                width: '80',
                resiable: true,
                typeAhead: true,
                allowBlank: false,
                handleHeight: 100, //   
                displayField: 'key',
                valueField: 'value',
                selectOnFocus: true,
                mode: 'local',
                selectOnFocus: true,
                triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
                readOnly: true,
                emptyText: '选择类型...',
                store: new Ext.data.Store({
                    data: [['45', '45折'], ['50', '50折'], ['55', '55折'], ['60', '60折'], ['65', '65折'], ['70', '70折'], ['75', '75折'], ['80', '80折']],
                    reader: new Ext.data.ArrayReader({
                        id: 0
                    }, [{
                            name: 'value'
                        }, {
                            name: 'key'
                        }])
                }), //数据储存到这个comboBox   
                anchor: '90%'
            });
                
            var rakeOff = new Ext.form.NumberField({
                fieldLabel: '<span class="red">*</span>B客户折扣',
                allowBlank: false,
                name: 'rake_off',
                anchor: '90%'
            });
                
            var dateBegin = new Ext.form.DateField({
                fieldLabel: '<span class="red">*</span>开始日期',
                name: 'date_begin',
                id: 'date_begin',
                format: 'Y-m-d', //格式化日期   
                width: '80',
                //disabledDays: [0,6],	//不让选择周六，周日   
                //disabledDaysText: "周末要休息",   
                invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                allowBlank: false,
                inputType: '2008-01-01',
                anchor: '90%',
                vtype: 'daterange',
                endDateField: 'date_end'
            });
            var dateEnd = new Ext.form.DateField({
                fieldLabel: '<span class="red">*</span>结束日期',
                name: 'date_end',
                id: 'date_end',
                format: 'Y-m-d', //格式化日期   
                width: '80',
                //disabledDays: [0,6],	//不让选择周六，周日   
                //disabledDaysText: "周末要休息",   
                invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
                allowBlank: false,
                inputType: '2008-01-01',
                anchor: '90%',
                vtype: 'daterange',
                startDateField: 'date_begin'
            });
                
            //自动出票
            var autoReleaseYes = new Ext.form.Radio({
                fieldLabel: '自动出票',
                name: 'auto_release',
                id: 'auto_release_yes',
                boxLabel: '是',
                checked: true,
                inputValue: '1'
            });
            var autoReleaseNo = new Ext.form.Radio({
                name: 'auto_release',
                id: 'auto_release_no',
                boxLabel: '否',
                checked: false,
                hideLabel: true,
                inputValue: '0'
            });
            //启用运价
            var isReleasedYes = new Ext.form.Radio({
                fieldLabel: '启用运价',
                name: 'is_released',
                id: 'is_released_yes',
                boxLabel: '是',
                checked: true,
                inputValue: '1'
            });
            var isReleasedNo = new Ext.form.Radio({
                name: 'is_released',
                id: 'is_released_no',
                boxLabel: '否',
                checked: false,
                hideLabel: true,
                inputValue: '0'
            });
            //客票类型
            var ticketPTBSP = new Ext.form.Radio({
                fieldLabel: '客票类型',
                name: 'ticket_payment_type',
                id: 'tpt_bsp',
                boxLabel: 'BSP',
                checked: true,
                inputValue: '1'
            });
            var ticketPTB2B = new Ext.form.Radio({
                name: 'ticket_payment_type',
                id: 'tpt_b2b',
                boxLabel: 'B2B',
                checked: false,
                hideLabel: true,
                inputValue: '0'
            });
            //转换PNR
            var cPNRYes = new Ext.form.Radio({
                fieldLabel: '转换PNR',
                name: 'conversion_pnr',
                id: 'conversion_pnr_yes',
                boxLabel: '是',
                checked: true,
                inputValue: '1'
            });
            var cPNRNo = new Ext.form.Radio({
                name: 'conversion_pnr',
                id: 'conversion_pnr_no',
                boxLabel: '否',
                checked: false,
                hideLabel: true,
                inputValue: '0'
            });
                
            var formCommonPrice = new Ext.form.FormPanel({
                labelWidth: 80,
                width: 550,
                frame: true,
                labelAlign: 'right',
                url: '/ticket/add_common_price_release',
                items: [airways, airportFrom,{
                        xtype: "itemselector",
                        name: "airports",
                        imagePath: "/images/multi_select",
                        drawUpIcon: false,
                        drawDownIcon: false,
                        drawLeftIcon: true,
                        drawRightIcon: true,
                        drawTopIcon: false,
                        drawBotIcon: false,
                        fieldLabel: "<span class='red'>*</span>目的地选择",
                        dataFields: ["code", "desc"],
                        //fromData: [[123, "One Hundred Twenty Three"], ["1", "One"], ["2", "Two"], ["3", "Three"], ["4", "Four"], ["5", "Five"], ["6", "Six"], ["7", "Seven"], ["8", "Eight"], ["9", "Nine"]],
                        fromData: <%=@airports_arraystr%>,
                        toData: [],
                        msWidth: 180,
                        msHeight: 300,
                        valueField: "code",
                        displayField: "desc",
                        //imagePath:"ext-ux/multiselect",
                        //switchToFrom:true,
                        toLegend: "已经选择的城市",
                        fromLegend: "可选城市",
                        toTBar: [{
                                text: "清除",
                                handler: function(){
                                    var i = formItemSelector.getForm().findField("itemselector");
                                    i.reset.call(i);
                                }
                            }]
                    }, flights, {
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .5,
                                layout: 'form',
                                border: false,
                                items: [discountFrom]
                            }, {
                                columnWidth: .5,
                                layout: 'form',
                                border: false,
                                items: [discountTo]
                            }]
                    }, rakeOff, {
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .5,
                                layout: 'form',
                                border: false,
                                items: [dateBegin]
                            }, {
                                columnWidth: .5,
                                layout: 'form',
                                border: false,
                                items: [dateEnd]
                            }]
                    }, {
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [autoReleaseYes]
                            }, {
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [autoReleaseNo]
                            }, {
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [isReleasedYes]
                            }, {
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [isReleasedNo]
                            }]
                    }, {
                        layout: 'column',
                        border: false,
                        items: [{
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [ticketPTBSP]
                            }, {
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [ticketPTB2B]
                            }, {
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [cPNRYes]
                            }, {
                                columnWidth: .25,
                                layout: 'form',
                                border: false,
                                items: [cPNRNo]
                            }]
                    }],
                buttons: [{
                        text: '确定',
                        handler: onItemClick //实际应用一般是处理fp.getForm.submit()事件   
                    }, {
                        text: '重置',
                        handler: function(){
                            formSpecialPosition.getForm().reset();
                        }
                    }, {
                        text: '帮助',
                        handler: function(){
                            formSpecialPosition.getForm().reset();
                        }
                    }]
            });
            //, flights, airwaysname, discountFrom, discountTo, dateBegin, dateEnd,isReleased,rakeOff,ticketPaymentType
            formCommonPrice.render("form-ct-itemselector");
            function onItemClick(item){
                if (formCommonPrice.form.isValid()) {
                    formCommonPrice.form.submit({
                        waitMsg: '正在提交......',
                        success: function(form, action){
                            Ext.MessageBox.alert("提示", "普通运价添加成功！");
                            tabs.getActiveTab().getUpdater().update("/ticket/common_price_released_list");
                        },
                        failure: function(form, action){
                            Ext.MessageBox.alert('提交错误消息', '提交失败');
                        }
                    });
                }
                else {
                    Ext.MessageBox.alert("提示", "请按要求填写带<span class='red'>*</span>的必输值！");
                }
            }
        })
    </script>
  </body>
</html>
